import requests
import time
import random

# 基本参数
# secid = "116.02688"  # 曹子金
secid = "1.000001"
ut = "fa5fd1943c7b386f172d6893dbfba10b"  # 随机用户标识
fields1 = "f1,f2,f3,f4,f5,f6"  # 可根据需要修改
fields2 = "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61"  # 可根据需要修改
klt = 101  # 日线
fqt = 1  # 前复权
beg = 20250101  # 起始时间
end = 20500101  # 结束时间
smplmt = 2053  # 数据限制
lmt = 1000000  # 条目限制
timestamp = int(time.time() * 1000)  # 当前时间戳

# 拼凑URL
url = f"https://push2his.eastmoney.com/api/qt/stock/kline/get?cb=jQuery{random.randint(10000000000000000000, 99999999999999999999)}_{timestamp}&secid={secid}&ut={ut}&fields1={fields1}&fields2={fields2}&klt={klt}&fqt={fqt}&beg={beg}&end={end}&smplmt={smplmt}&lmt={lmt}&_={timestamp}"

# 发送请求
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
}

response = requests.get(url, headers=headers)

# 检查响应
if response.status_code == 200:
    data = response.text
    print(data)  # 根据需要进一步处理数据
else:
    print("请求失败，状态码：", response.status_code)